#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

int n, m;
ll sum[N];
int q[N];
int head = 1, tail = 1;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> m;
  while (m--) {
    int op, x;
    cin >> op;
    if (op == 1) {
      cin >> x;
      q[tail] = x;
      sum[tail] = sum[tail - 1] + x;
      ++tail;
    } else if (op == 2) {
      head++;
    } else {
      cin >> x;
      x += head - 2;
      cout << sum[x] - sum[head - 1] << endl;
    }
  }
  return 0;
}